
char * appendpath(const char *dir, const char *file, const char *ext, char *out)
{
	unsigned dirlen = __builtin_strlen(dir);
	unsigned filelen = __builtin_strlen(file);
	
	__builtin_memcpy(out, dir, dirlen);
	if (dirlen > 0 && (dir[dirlen-1] != '/' && dir[dirlen-1] != '\\'))
		out[dirlen++] = '/';
	__builtin_memcpy(&out[dirlen], file, filelen);
	out[dirlen+filelen++] = '.';
	__builtin_strcpy(&out[dirlen+filelen], ext);
	return out;
}
